package vip.xiaonuo.smzq.modular.lifecycle.mapper.module;
import cn.hutool.core.lang.Dict;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import vip.xiaonuo.smzq.modular.lifecycle.entity.KclCb08Xzqh;
import vip.xiaonuo.smzq.modular.lifecycle.entity.KclWjglb;
import vip.xiaonuo.smzq.modular.lifecycle.po.QueryYearStorePO;
import vip.xiaonuo.smzq.modular.lifecycle.vo.QuerYearStoreVO;

import java.util.List;

/**
 * <p>
 * 资料上传文件关联表 Mapper 接口
 * </p>
 *
 * @author 于彦飞
 * @since 2024-03-20
 */
@Mapper
@Repository(value = "LifeCycleMapper")
public interface LifeCycleMapper {
//    统计矿山的矿石类型，资源储量类型的储量sql
    public static final String staticsYearStoreSQL = "select" +
        " cb.mc, " +
        " kl.kcmc," +
        " kz.zycllx," +
        " kz.nd as year," +
        " kz.kslx," +
        " kz.kcdm," +
        " case  " +
        " when (select k6.jsldw from kcl_cb06_kc k6 where k6.kcdm = kz.kcdm) in ('',null) then sum(kz.ksl)" +
        " else sum(kz.jsl) end as total" +
        " FROM kcl_zycl kz " +
        " left join kcl_cb13_zycllx cb on kz.zycllx = cb.dm" +
        " left join kcl_cb06_kc kl ON kz.kcdm = kl.kcdm" +
        " where kz.zycllx in ('TM','KZ','TD')" +
        " and kz.kqbh = #{query.mineralCode}" +
        " and kz.djflbh = #{query.regClassCode}" +
//        " and kz.nd = #{query.year}" +
        " and kz.zycllb = #{query.zycllb}" +
        " group by  kz.zycllx,kz.nd,kz.kslx,cb.mc,kz.kslx,kl.kcmc,kz.kcdm";
    /**
     * 统计年度储量vo
     * @return
     */
//    @Select("select t1.year,sum(t1.total) as storeVal from ("+staticsYearStoreSQL+") t1 group by t1.year")
    List<QuerYearStoreVO> staticsYearStore(@Param("query") QueryYearStorePO queryYearStorePO);

    List<QuerYearStoreVO> staticsMineralStorerVal(@Param("query") QueryYearStorePO queryYearStorePO);

    @Select("SELECT t1.pkid FROM life_cycle_mine_store t LEFT JOIN kcl_zlsc t1 ON (t1.djflbh = t.reg_class_code AND t1.nd = t.year AND t1.kqbh = t.mineral_code) WHERE (to_char(t.store_date, 'YYYY.MM.DD') = #{date})")
    List<String> queryWJJIdList(@Param("date") String date);


}
